(function () {
    var io = ppt.io;
    function Roledetails() {
        Roledetails.super(this);
        this.ASSETS = {
            RES: ASSETS.ROLESERES,
            TYPE: "simple"
        }
        this._details = [];        // 角色详情
        this.BG = null;      // 公共背景龙骨
        this.ui = null;
        this.detailBox = null;
        this._expIndex = roleNumlr = ppt.expIndex;
        this.init();
    }
    Laya.class(Roledetails, "Scene.Roledetails", Laya.Sprite);
    var _proto = Roledetails.prototype;
    _proto.destroy = function () {
        Laya.Sprite.prototype.destroy.call(this, true);

        this._details = null;        // 角色详情
        this.BG = null;      // 公共背景龙骨
        this.ui = null;
        this.detailBox = null;

    }
    _proto.init = function () {
        this.size(GAME_CONFIG.WIDTH, Laya.stage.height);
        io.register("role::roleList", this, this.listChoosebtn);
        io.register("role::advance", this, this.advanceStar);
        io.register("role::skillUp", this, this.upgradeData);
        io.register("pve::wait", this, this.pvehome);
        io.register("game::ready", this, this.gameReady);
    }
    _proto.createUI = function () {
        var figureDetails = [];
        //公共背景龙骨动画
        var BG = utils.createSkeleton('res/public/public_bg');
        BG.pos(GAME_CONFIG.WIDTH / 2, Laya.stage.height / 2);

        var roletab = new Com.Role.Tab(function (direction) {
            this.direction = direction;
            this.detailsScroll();
        }.bind(this));
        roletab.y = Laya.stage.height / 2 - roletab.height / 2;
        this.ui = roletab;
        this.BG = BG;
        BG.play('public_bg', true);
        this.addChildren(BG, roletab);
        var detailBox = new Laya.Box();
        this.detailBox = detailBox;
        this.addChild(detailBox);
        this.detailBox.y = Laya.stage.height / 2 - this.detailBox.height / 2 + 50;
        for (var i = 0; i < 4; i++) {
            this._details[i] = new Com.Role.box(i);
            detailBox.addChild(this._details[i]);

        }

        if (this._expIndex == 0) {
            this._details[0].x = 60;
            this._details[1].x = 1334 * 1 + 60;
            this._details[2].x = 1334 * 2 + 60;
            this._details[3].x = -1334 + 60;

        }
        else if (this._expIndex == 1) {
            this._details[0].x = -1334 + 60;
            this._details[1].x = 60;
            this._details[2].x = 1334 * 1 + 60;
            this._details[3].x = 1334 * 2 + 60;

        }
        else if (this._expIndex == 2) {
            this._details[0].x = 1334 * 2 + 60;
            this._details[1].x = -1334 + 60;
            this._details[2].x = 60;
            this._details[3].x = 1334 * 1 + 60;
        }
        else if (this._expIndex == 3) {
            this._details[0].x = 1334 * 2 + 60;
            this._details[1].x = 1334 * 1 + 60;
            this._details[2].x = -1334 + 60;
            this._details[3].x = 60;

        }

    }
    _proto.listChoosebtn = function (data) {
        this.data = data;
        for (var i = 0; i < 4; i++) {
            this._details[i].upData(data.role[i]);
        }

    }

    _proto.advanceStar = function (data) {
        this._details[roleNumlr].boxData(data);

    }
    _proto.upgradeData = function (data) {
        this._details[roleNumlr].upSkillData(data);
    }
    _proto.detailsScroll = function () {
        for (var i = 0; i < 4; i++) {
            this._details[i].visible = true;
            switch (this.direction) {
                case 'next':
                    if (this._details[i].x == (-1334 + 60)) {
                        Laya.Tween.to(this._details[i], { x: (1334 * 2 + 60) }, 300, Laya.Ease['linearIn']);

                    } else if (this._details[i].x == (1334 * 2 + 60)) {
                        Laya.Tween.to(this._details[i], { x: (1334 * 1 + 60) }, 300, Laya.Ease['linearIn']);

                    } else if (this._details[i].x == (1334 * 1 + 60)) {
                        Laya.Tween.to(this._details[i], { x: 60 }, 300, Laya.Ease['linearIn']);
                        roleNumlr = i;
                        this._expIndex = i;
                    } else if (this._details[i].x == 60) {

                        Laya.Tween.to(this._details[i], { x: (-1334 + 60) }, 300, Laya.Ease['linearIn']);
                    }
                    break;
                case 'prev':
                    if (this._details[i].x == 60) {
                        Laya.Tween.to(this._details[i], { x: (1334 * 1 + 60) }, 300, Laya.Ease['linearIn']);

                    } else if (this._details[i].x == (1334 * 1 + 60)) {
                        Laya.Tween.to(this._details[i], { x: (1334 * 2 + 60) }, 300, Laya.Ease['linearIn']);
                    } else if (this._details[i].x == (1334 * 2 + 60)) {
                        Laya.Tween.to(this._details[i], { x: (-1334 + 60) }, 300, Laya.Ease['linearIn']);
                    } else if (this._details[i].x == (-1334 + 60)) {
                        Laya.Tween.to(this._details[i], { x: 60 }, 300, Laya.Ease['linearIn']);
                        roleNumlr = i;
                    }
                    break;
            }
        }
    }
    _proto.pvehome = function (data) {
        var config = {
            msg: data.msg,
            close: true,
            btn: {
                btnCancel: false,
                btnConfirm: {
                    skin: "confirm"
                }
            }
        }
        switch (data.code) {
            case 103://pve次数已用完
            case 116://pvp无法进入pve
                ppt.director.popScene(new Alert.Public(config));
                break;
        }
    }
    _proto.gameReady = function (data) {
        ppt.director.runScene(new Scene.Game(data));
    }

    _proto.onAdd = function () {
        this.createUI();

    }
    _proto.onEnter = function () {
        io.emit({ "cmd": "role::roleList", params: {} });

        ppt.header.enter("roledetails");
    }
    _proto.onExit = function () {
        io.unregister("role::roleList", this.listChoosebtn);
        io.unregister("role::skillUp");
        io.unregister("role::advance");
        io.unregister("pve::wait", this.pvehome);
        io.unregister("game::ready", this.gameReady);
        this.destroy(true);
    }
    _proto.onResize = function (height) {
        this.BG.x = 667;
        this.BG.y = height / 2;
        this.ui.y = height / 2 - this.ui.height;
        this.detailBox.y = Laya.stage.height / 2 - this.detailBox.height / 2 + 50;
    }
})();
